#include "agent.h"


agent::agent(void)
{
}

agent::agent(shape_T iType, vertex iPos, AVector iVel, team_T iTeam) {
	type = iType;
	position = iPos;
	velocity = iVel;
	if (velocity.length() == 0) direction = 0;
	else direction = velocity.getDirection();
	team = iTeam;
	goal = vertex(0,0);                    // Dummy initial goal - Need to change?
	
	// Determine speed limit based on agent type (for initialization)
	switch (iType) {
	case TRIANGLE:
		speedLimit = (float).1;
		hp = 10;
		atkPower = 10;
		atkInterval = 5000;
		break;
	case CIRCLE:
		speedLimit = (float).1;
		hp = 15;
		atkPower = 2;
		atkInterval = 2500;
		break;
	case RECTANGLE:
		speedLimit = (float).1;
		hp = 40;
		atkPower = 5;
		atkInterval = 4000;
		break;
	}

	atkTimer = atkInterval;

	// Set target pointer to null - no target
	target.targetObj = 0;
	target.inRange = false;
}


agent::~agent(void)
{
}

vertex agent::getTargetPosition() {
	vertex returnPos = (target.isAgent) ? ((agent*)target.targetObj)->position
					                    : ((structure*)target.targetObj)->position;

	return returnPos;
}

// Returns true if target is destroyed
// NOTE: only returns true if this particular attack destroys the target
bool agent::atkTarget() {
	if (target.isAgent) {
		agent * targetAgent = (agent*)target.targetObj;
		if (targetAgent->hp <= 0) return false;
		targetAgent->hp -= this->atkPower;
		

		switch (targetAgent->type) {
		case TRIANGLE:
			cout << "Triangle HP Remaining:" << targetAgent->hp << endl;
			break;
		case CIRCLE:
			cout << "Circle HP Remaining:" << targetAgent->hp << endl;
			break;
		case RECTANGLE:
			cout << "Rectangle HP Remaining:" << targetAgent->hp << endl;
			break;
		}


		if (targetAgent->hp <= 0)
			return true;
		else 
			return false;
	}
	else {
		structure * targetStructure = (structure*)target.targetObj;
		if (targetStructure->hp <= 0) return false;
		targetStructure->hp -= this->atkPower;

		switch (targetStructure->type) {
		case structure::CITADEL:
			cout << "Citadel HP Remaining:" << targetStructure->hp << endl;
			break;
		case structure::SUPPLY:
			cout << "Supply HP Remaining:" << targetStructure->hp << endl;
			break;
		case structure::TOWER:
			cout << "Tower HP Remaining:" << targetStructure->hp << endl;
			break;
		}

		if (targetStructure->hp <= 0)
			return true;
		else 
			return false;
	}
}